package io.renren.modules.sys.controller;

import java.util.Arrays;
import java.util.Map;

import io.renren.common.utils.Result;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.renren.modules.sys.entity.PocketTemplateEntity;
import io.renren.modules.sys.service.PocketTemplateService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;


/**
 * 账目模板表
 *
 * @author Amadeus
 * @email 313300182@qq.com
 * @date 2020-12-29 10:00:53
 */
@RestController
@RequestMapping("sys/pockettemplate")
public class PocketTemplateController {
    @Autowired
    private PocketTemplateService pocketTemplateService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("sys:pockettemplate:list")
    public R list(@RequestParam Map<String, Object> params) {
        PageUtils page = pocketTemplateService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("sys:pockettemplate:info")
    public R info(@PathVariable("id") Long id) {
        PocketTemplateEntity pocketTemplate = pocketTemplateService.getById(id);

        return R.ok().put("pocketTemplate", pocketTemplate);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("sys:pockettemplate:save")
    public Result save(@RequestBody PocketTemplateEntity pocketTemplate) {

        return pocketTemplateService.savePocket(pocketTemplate);
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("sys:pockettemplate:update")
    public Result update(@RequestBody PocketTemplateEntity pocketTemplate) {

        return pocketTemplateService.updatePocket(pocketTemplate);
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("sys:pockettemplate:delete")
    public R delete(@RequestBody Long[] ids) {
        pocketTemplateService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
